# -*- coding: utf-8 -*-

import time

from PageClass.boe_EmployeeLoanClass.Class_EmployeeLoanBoe import Class_EmployeeLoanBoe
from TestCases.common import LoginDepend
from TestCases.common._baseClass import _BaseClass
from Util import config, logger, record


class BoeSubmit(_BaseClass):

    def __init__(self, isExit=True):
        self.isExit = isExit
        self.login = LoginDepend('ecsHost', 'user')
        self.EmployeeLoan = Class_EmployeeLoanBoe(self.login.driver)

    def __exit__(self, *args):
        if super().__exit__(*args):
            if self.isExit:
                self.exit()
        else:
            self.exit()

    def exit(self):
        self.EmployeeLoan.driver.quit()

    def submit(self, boe_data):
        # 打开费报
        logger.info(f"费报地址为：{config.urlDict.url.ecsHost}")  # .\Config\test\UrlConfig.yml

        # 打开员工借款单
        self.EmployeeLoan.open_boe(boe_data.areaType, boe_data.boeType, boe_data.operationType)

        # 获取单号
        boeNo = self.EmployeeLoan.getBoeNum()
        record.writeDataToRecord({'boeNo': boeNo})

        # 主表区：业务类型
        operationType = boe_data.operationType
        self.EmployeeLoan.input_operationType(operationType)

        # 主表区：备注
        boeAbstract = boe_data.boeAbstract
        self.EmployeeLoan.inputboeAbstract(boeAbstract)

        # 借款明细区：业务类型-小类
        TypeId_Name = boe_data.TypeId_Name
        self.EmployeeLoan.SelectType(TypeId_Name)

        # 借款明细区：总金额
        expenseAmount = boe_data.expenseAmount
        self.EmployeeLoan.inputExpenseAmount(expenseAmount)

        # 借款明细区：项目
        Project = boe_data.Project
        self.EmployeeLoan.inputProject(Project)

        # # 保存单据
        # self.EmployeeLoan.click_boeSaveButton()
        # time.sleep(5)

        # 提交单据
        message = self.EmployeeLoan.click_boeSubmitButton()

        return message
